// core/Time.h

#ifndef _CORE_Time_H_
#define _CORE_Time_H_

#ifndef _CORE_Types_H_
#include <core/Types.h>
#endif

namespace CORE
{

class Time
{
public:
	Time();
	Time(const Time & aTime);
	Time(uint32_t ulTime);

	// Accessors
	uint32_t		GetTime() const {
		return m_ulTime;
	}
	void			SetTime(uint32_t ulTime) {
		m_ulTime = ulTime;
	}
	void			SetTime(const Time & aTime) {
		m_ulTime = aTime.m_ulTime;
	}

	// APIs
	int		TimeInSecondsAsInt() const {
		return static_cast<int>((float)(m_ulTime * 0.001f));
	}
	float	TimeInSecondsAsFloat() const {
		return (static_cast<float>(m_ulTime) * 0.001f);
	}
	double	TimeInSecondsAsDouble() const {
		return (static_cast<double>(m_ulTime) * 0.001f);
	}
	void	SetFloat(float f) {
		m_ulTime = static_cast<uint32_t>( f * 1000.0f );
	}
	void	SetDouble(double d) {
		m_ulTime = static_cast<uint32_t>( d * 100.0f );
	}

	// Operators
	Time operator + ( const Time & aTime ) const;
	Time operator - ( const Time & aTime ) const;
	Time operator * ( const Time & aTime ) const;
	Time operator / ( const Time & aTime ) const;
	void operator +=( const Time & aTime );
	void operator -=( const Time & aTime );
	void operator *=( const Time & aTime );
	void operator /=( const Time & aTime );
	bool operator ==( const Time & aTime ) const;
	bool operator !=( const Time & aTime ) const;

	bool operator >	( const Time & aTime ) const;
	bool operator >=( const Time & aTime ) const;
	bool operator <	( const Time & aTime ) const;
	bool operator <=( const Time & aTime ) const;
	
private:

	uint32_t		m_ulTime;
};

// inline functions

inline Time::Time()
	: m_ulTime(0)
{
}

inline Time::Time(uint32_t ulTime)
	: m_ulTime(ulTime)
{

}

inline Time::Time(const Time & aTime)
	: m_ulTime(aTime.m_ulTime)
{

}

inline Time Time::operator + (const Time & aTime) const
{
	return Time(m_ulTime + aTime.m_ulTime);
}

inline Time Time::operator - (const Time & aTime) const
{
	return Time(m_ulTime - aTime.m_ulTime);
}

inline Time Time::operator * (const Time & aTime) const
{
	return Time(m_ulTime * aTime.m_ulTime);
}

inline Time Time::operator / (const Time & aTime) const
{
	return Time(m_ulTime / aTime.m_ulTime);
}

inline void Time::operator += (const Time & aTime)
{
	m_ulTime += aTime.m_ulTime;
}

inline void Time::operator -= (const Time & aTime)
{
	m_ulTime -= aTime.m_ulTime;
}

inline void Time::operator *= (const Time & aTime)
{
	m_ulTime *= aTime.m_ulTime;
}

inline void Time::operator /= (const Time & aTime)
{
	m_ulTime /= aTime.m_ulTime;
}

inline bool Time::operator == (const Time & aTime) const
{
	return (m_ulTime == aTime.m_ulTime);
}

inline bool Time::operator != (const Time & aTime) const
{
	return (m_ulTime != aTime.m_ulTime);
}

inline bool Time::operator > (const Time & aTime) const
{
	return m_ulTime > aTime.m_ulTime;
}

inline bool Time::operator >= (const Time & aTime) const
{
	return m_ulTime >= aTime.m_ulTime;
}

inline bool Time::operator < (const Time & aTime) const
{
	return m_ulTime < aTime.m_ulTime;
}

inline bool Time::operator <= (const Time & aTime) const
{
	return m_ulTime <= aTime.m_ulTime;
}

}; // namespace CORE

#endif